enum Rank:String{
	case ace = "0"
	case two,three, four,five,six,seven,eight,nine,ten
	case jack,queen,king
	
	func simpleDescription() -> String{
		switch self{
			case .ace:
				return "ace"
			case .jack:
				return "jack"
			case .queen:
				return "queen"
			case .king:
				return "king"
			default:
				return String(self.rawValue)
		}
	}
}

let ace = Rank.ace
print(ace)

let aceRawValue = ace.rawValue

print(aceRawValue)

//枚举初始化

var rank  = Rank(rawValue:"5")

print( Rank.king.rawValue)
print( Rank.king.simpleDescription())

if let convertedRank = Rank(rawValue:"3"){
	let desc = convertedRank.simpleDescription()
	print(desc)
}

enum Suit:String{
	case spades,hearts,diamonds,clubs
	case red,black,club,square
	func simpleDescription() -> String{
		switch self{
			case .spades:
				return "spades"
			case .hearts:
				return "hearts"
			case .diamonds:
				return "diamonds"
			case .clubs:
				return "clubs"
//如果全部枚举完成  就不执行default
			default:
				return String(self.rawValue)
		}
	}
	
	func color() -> String{
		switch self{
			case .red:
				return "red"
			case .black:
				return "black"
			case .club:
				return "club"
			default :
				return "red"
		}
	}

}

let hearts = Suit.hearts

let heartsDesc = hearts.simpleDescription()
print(heartsDesc)

var com = hearts.color()+"\t"+hearts.simpleDescription()
print(com)

//结构体
//	One of the most important differences between structures and classes is that structures are always copied when they are passed 	around in your code, but classes are passed by reference.

struct Card{
	var rank:Rank
	var suit:Suit
	
	func simpleDescription() -> String{
		return "The \(rank.simpleDescription()) of \(suit.simpleDescription())"
	}
}

let threeOfSpades = Card(rank:.three,suit:.spades)

let threeOfSpadesDesc = threeOfSpades.simpleDescription()

print(threeOfSpadesDesc)

//
enum ServerResponse{
	case result(String,String)
	case failure(String)
}

//方法也可以枚举
let succes:ServerResponse = ServerResponse.result("6.00 pm","8:09 pm")

let failure:ServerResponse = ServerResponse.failure("Out of cheese.")

switch succes{
	case let .failure(message):
		print("Failure...\(message)")
	case let .result(sunrise,sunset):
		print("Sunrise is at \(sunrise) and sunset is at \(sunset)")
}

switch failure{
	case let .failure(message):
		print("Failure...\(message)")
	case let .result(sunrise,sunset):
		print("Sunrise is at \(sunrise) and sunset is at \(sunset)")
}








































